const Router = require("koa-router");
const router = new Router({ prefix: "/bl-user" });
const {
  register,
  login,
  getUserInfo,
  handleLoginControl,
  handleCallback,
  handleGetUserInfo,
  queryUserListControl,
  queryRoleListControl, 
  handleWeiboLoginControl,
  getUserInfoControl,
  modifyUserById,
  modifyPwd
} = require("../controller/userController");
const {
  UserValidate,
  UserIsExist,
  crptyPassword,
  verifyOldPwd
} = require("../middlewares/user.middle");
const { verifyLogin, verifyToken } = require("../middlewares/auth.middle");
const {uploadOss} = require("../middlewares/upload.middle")
/**
 * @swagger
 * /bl-user/userinfo:
 *  get:
 *      tags:
 *         - User
 *
 * @swagger
 * /bl-user/login:
 *  post:
 *      tags:
 *          - User
 * @swagger
 * /bl-user/register:
 *  post:
 *      tags:
 *          - User
 *
 *
 */

// 用户的token过期未处理。
router.post("/queryRoleList",queryRoleListControl);
router.post("/queryUserList", queryUserListControl);
router.get("/getThirdUserInfo", handleGetUserInfo);
// gitee回调
router.get("/callback", handleCallback);
router.get("/oauth/gitee", handleLoginControl);
router.get("/weiboCallback",handleCallback);
router.get("/oauth/weibo",handleWeiboLoginControl)
router.get("/userinfo", verifyToken, getUserInfo);
router.post("/login", UserValidate, verifyLogin, login);
router.post("/register", UserValidate, UserIsExist, crptyPassword, register);
router.post("/getUserInfo",getUserInfoControl);
// 修改密码（只允许账号登录的进行修改）
router.post("/modifyPwd",verifyOldPwd,modifyPwd);

// 编辑用户信息

router.post("/modify",uploadOss,modifyUserById);
module.exports = router;
